package com.fyzk.activity.lottery.jc.football.newJz;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;

import com.fyzk.activity.lottery.jc.football.JCZQ_HG_ZhiFuActivity;
import com.fyzk.activity.lottery.jc.football.adapter.JCZQ_HG_Adapter;
import com.fyzk.activity.lottery.zc.tz_dialog.JZ_HG_Pop;
import com.fyzk.bean.JCZQResponseInfo;
import com.tyjc.lottery.R;
import com.fyzk.utils.LotteryIDUtils;
import com.fyzk.utils.ScreenUtils;
import com.fyzk.utils.Utils;

import java.util.List;


public class JCZQ_HG_Fragment extends JC_OpenPop_BaseFragment {

    private JCZQ_HG_Adapter adapter;

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        reTry();
    }

    @Override
    protected void init(View view) {
        super.init(view);
        rb_gb.setVisibility(View.GONE);
    }

    @Override
    protected Class getZhiFuActivity() {
        // TODO Auto-generated method stub
        return JCZQ_HG_ZhiFuActivity.class;
    }

    @Override
    protected void adapterChange(List<JCZQResponseInfo> infos) {
        super.adapterChange(infos);
        if(adapter!=null){
            adapter.setCount(changCiNum);
            notifyList();
        }
    }


    @Override
    protected int getLotteryType() {
        // TODO Auto-generated method stub
        return LotteryIDUtils.JZHH_LOTTERY_ID_INT;
    }

    @Override
    protected void initGameQueueView() {
        adapter = new JCZQ_HG_Adapter(getContext(), infos, this);
        center_list.setAdapter(adapter);
        for (int i = 0; i < adapter.getGroupCount(); i++) {
            center_list.expandGroup(i);
        }
    }

    @Override
    protected int getTitleStringRes() {
        // TODO Auto-generated method stub
        return R.string.jcz_hg;
    }

    @Override
    protected void toZhanKai(int grouppostion, int childposition) {
        int height = Utils.dip2px(440f);
        JZ_HG_Pop JZHGPop = new JZ_HG_Pop(getContext(), WindowManager.LayoutParams
                .MATCH_PARENT, height, infos.get(grouppostion).matchDatas.get(childposition),changCiNum);

        JZHGPop.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                setBackgroundAlpha(1.0f);
                adapterChange(infos);
                adapter.notifyDataSetChanged();
            }

        });
        setBackgroundAlpha(0.5f);
        JZHGPop.showAtLocation(getView(), Gravity.NO_GRAVITY, 0, ScreenUtils.getInstance()
                .getHeight() -
                height);
    }

    public void setBackgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams lp = getActivity().getWindow()
                .getAttributes();
        lp.alpha = bgAlpha;
        getActivity().getWindow().setAttributes(lp);
    }


    @Override
    public void notifyList() {
        adapter.notifyDataSetChanged();
    }

}
